package com.info.zhiduoduo.core.dto.transferpay;

import com.info.zhiduoduo.repository.entity.crowdsource.CrowdsourceTradeRecordItem;

import java.math.BigDecimal;
import java.math.RoundingMode;

import javax.validation.constraints.NotEmpty;

import com.info.zhiduoduo.repository.entity.order.TradeRecord;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class TransferAgentPayFormBean {

	/** 4:传化武圣 5:传化信圣 */
	private int paymentMerchant;
	/**  平台交易编号 */
	@NotEmpty
	private String tradeNo;
	/** 交易金额(单位元) */
	private BigDecimal tradeamount;
	/** 交易说明 */
	private String purpose;
	/** 银行卡号 */
	private String acctNo;
	/** 账户姓名 */
	private String acctName;
	/** 银行名(对公账户需要) */
	private String bankName;
	/** 国内对公填写支行名 */
	private String branchNo;
	/** 银行行号,联行号 */
	private String bankNo; //	否	字符	12		银行联行号(选填，银行卡类型为企业时填写可提高处理效率)
	/** 1:代表个人账户  2:代表企业账户 */
	private int acctType;
	/** 省 */
	private String province; //	否	字符	60		省份(银行卡类型为企业时必填，个人选填)
	/** 市 */
	private String city; //	否	字符	60		城市(银行卡类型为企业时必填，个人选填)

	public static TransferAgentPayFormBean of(TradeRecord tradeRecord) {
		return new TransferAgentPayFormBean()
				.setPaymentMerchant(tradeRecord.getMerchantid())
				.setTradeNo(tradeRecord.getTradeno())
				.setTradeamount(tradeRecord.getTradeamount().setScale(2, RoundingMode.DOWN))
				.setPurpose(tradeRecord.getPurpose())
				.setAcctNo(tradeRecord.getAcctno())
				.setAcctName(tradeRecord.getAcctname())
				.setAcctType(tradeRecord.getAccttype())
				.setBankName(tradeRecord.getBankname())
				.setBranchNo(tradeRecord.getBranchName())
				.setBankNo(tradeRecord.getBankno())
				.setProvince(tradeRecord.getBankProvince())
				.setCity(tradeRecord.getBankCity());
	}

	public static TransferAgentPayFormBean of(CrowdsourceTradeRecordItem recordItem, Integer merchantId) {
		return new TransferAgentPayFormBean().setPaymentMerchant(merchantId)
				.setTradeNo(recordItem.getTradeNo())
				.setTradeamount(recordItem.getTradeamount().setScale(2, RoundingMode.DOWN))
				.setPurpose(recordItem.getPurpose())
				.setAcctNo(recordItem.getAcctno())
				.setAcctName(recordItem.getAcctname())
				.setAcctType(recordItem.getAccttype())
				.setBankName(recordItem.getBankname())
				.setBankNo(recordItem.getBankno());
	}
}
